package com.market.controller.admin;

import com.market.bean.bo.admin.AdminConfigExpress;
import com.market.bean.bo.admin.AdminConfigMallBo;
import com.market.bean.bo.admin.AdminConfigOrderBo;
import com.market.bean.bo.admin.AdminConfigWXBo;
import com.market.bean.common.BaseRespVo;
import com.market.exception.ValidationException;
import com.market.service.admin.AdminConfigService;
import com.market.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @Author:WalterChan
 * @Decription:AdminConfigController
 * @Date Created in 2022-12-30-21:11
 */

@RestController
@RequestMapping("admin/config")
public class AdminConfigController {

    @Autowired
    AdminConfigService adminConfigService;

    @GetMapping("mall")
    public BaseRespVo getMall(){
//        首次访问什么都没有的话直接返回数据库内有的信息

            /*HashMap<String,String> result=  adminConfigService.listMall();
            return BaseRespVo.ok(result);
            */

        ArrayList<String> list = AdminConfigMallBo.getList();
        HashMap<String, String> map = adminConfigService.list(list);
        return BaseRespVo.ok(map);

//
    }
    @PostMapping("mall")
    public BaseRespVo postMall(@RequestBody @Valid AdminConfigMallBo adminConfigMallBo, BindingResult bindingResult) throws ValidationException {
//        首次访问什么都没有的话直接返回数据库内有的信息
        ValidationUtil.valid(bindingResult);
        BaseRespVo msg = ValidationUtil.getBaseRespVo(bindingResult);
        if (msg!=null) return msg;

        HashMap<String, String> map = AdminConfigMallBo.getMap(adminConfigMallBo);
        HashMap<String, String> result = adminConfigService.update(map);
        return BaseRespVo.ok(result);


    }

    @GetMapping("express")
    public BaseRespVo getExpress(){
//        首次访问什么都没有的话直接返回数据库内有的信息
        ArrayList<String> list = AdminConfigExpress.getList();
        HashMap<String,String> result=  adminConfigService.list(list);
        return BaseRespVo.ok(result);
    }

    @PostMapping("express")
    public BaseRespVo postExpress(@RequestBody @Valid AdminConfigExpress adminConfigExpress, BindingResult bindingResult) throws ValidationException {
        ValidationUtil.valid(bindingResult);
        BaseRespVo msg = ValidationUtil.getBaseRespVo(bindingResult);
        if (msg!=null) return msg;
//        首次访问什么都没有的话直接返回数据库内有的信息

        HashMap<String, String> map = AdminConfigExpress.getMap(adminConfigExpress);
        HashMap<String,String> result= adminConfigService.update(map);
        return BaseRespVo.ok(result);
    }

    @GetMapping("order")
    public BaseRespVo getOrder(){
//        首次访问什么都没有的话直接返回数据库内有的信息

        ArrayList<String> list = AdminConfigOrderBo.getList();
        HashMap<String,String> result=  adminConfigService.list(list);
        return BaseRespVo.ok(result);
    }

    @PostMapping("order")
    public BaseRespVo postOrder(@RequestBody @Valid AdminConfigOrderBo adminConfigOrderBo, BindingResult bindingResult) throws ValidationException {
//        首次访问什么都没有的话直接返回数据库内有的信息
        ValidationUtil.valid(bindingResult);
        BaseRespVo msg = ValidationUtil.getBaseRespVo(bindingResult);
        if (msg!=null) return msg;

        HashMap<String, String> map = AdminConfigOrderBo.getMap(adminConfigOrderBo);
        HashMap<String,String> result= adminConfigService.update(map);
        return BaseRespVo.ok(result);
    }

    @GetMapping("wx")
    public BaseRespVo getWX(){
//        首次访问什么都没有的话直接返回数据库内有的信息

        ArrayList<String> list = AdminConfigWXBo.getList();
        HashMap<String,String> result=  adminConfigService.list(list);
        return BaseRespVo.ok(result);
    }

    @PostMapping("wx")
    public BaseRespVo postWX(@RequestBody @Valid AdminConfigWXBo adminConfigWXBo, BindingResult bindingResult) throws ValidationException {
//        首次访问什么都没有的话直接返回数据库内有的信息

        ValidationUtil.valid(bindingResult);
        BaseRespVo msg = ValidationUtil.getBaseRespVo(bindingResult);
        if (msg!=null) return msg;

        HashMap<String, String> map = AdminConfigWXBo.getMap(adminConfigWXBo);
        HashMap<String, String> result = adminConfigService.update(map);
        return BaseRespVo.ok(result);


    }




}
